package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Role;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色控制层
 *
 * @author by 春风能解释
 * <p>
 * 2023/11/15
 */
@RestController
@RequestMapping("/role")
@Api(value = "角色控制层", tags = "角色操作访问接口")
public class RoleController {

    /**
     * 角色业务层注入
     */
    @Autowired
    private RoleService roleService;

    /**
     * 条件查询角色
     *
     * @param current 当前页码
     * @param size    每页长度
     * @param role    条件
     * @return JSON
     */
    @GetMapping
    @ApiOperation(value = "分类筛选角色信息")
    public JsonRequest<List<Role>> lookRole(
            @ApiParam(value = "当前页数", required = true)
            @RequestParam Integer current,
            @ApiParam(value = "每页长度", required = true)
            @RequestParam Integer size,
            @ApiParam(value = "条件", required = true)
            Role role) {
        return roleService.lookRole(current, size, role);
    }

    /**
     * 添加一条角色信息
     *
     * @param role 待添加的角色
     * @return JSON
     */
    @PostMapping
    @ApiOperation(value = "新增一条角色信息")
    public JsonRequest<Integer> addOneRole(
            @ApiParam(value = "待添加的角色信息", required = true)
            @RequestBody Role role) {
        return roleService.addOneRole(role);
    }

    /**
     * 修改一条角色信息
     *
     * @param role 待修改的角色信息
     * @return JSON
     */
    @PutMapping
    @ApiOperation(value = "修改一条角色信息")
    public JsonRequest<Integer> updateOneRole(
            @ApiParam(value = "待修改的角色信息", required = true)
            @RequestBody Role role) {
        return roleService.updateOneRole(role);
    }

    /**
     * 批量删除角色
     *
     * @param ids ID
     * @return JSON
     */
    @DeleteMapping
    @ApiOperation(value = "批量删除角色信息")
    public JsonRequest<Integer> deleteRole(
            @ApiParam(value = "待删除的角色ID", required = true)
            @RequestBody List<String> ids) {
        return roleService.deleteRole(ids);
    }
}
